<?php
class dispatcher {
	/*
	 * 查询数组
	 */
	private static $query = array();
	var $config = array();
	
	public static function init() {
		
	}
	
	/**
	 * 获取查询数组
	 */
	public static function getQuery() {
		if(empty(self::$query))
			parse_str($_SERVER['QUERY_STRING'], self::$query);

		return self::$query;
	}
	
	/**
	 * 获取控制器名称
	 */
	public static function getController() {
		$query = self::getQuery();
		return $query['c'];
	}
	
	/**
	 * 获取动作名称
	 */
	public static function getAction() {
		$query = self::getQuery();
		return $query['a'];
	}
	
	/*
	 * 根据请求参数实例化控制器并执行相应动作
	 */
	public static function run() {
		$c = self::getController();
		$a = self::getAction();
		$className = $c.'Controller';
		if(!class_exists('indexController'))
			die('c');
		if(!method_exists($className, $a))
			die('a');
		require './controller/'.$c.'.php';
		$obj = new $className();
		$obj->$a();
	}
	
} // class dispatcher end